#include<stdio.h>
#include<stdlib.h>
int main()
{
	int* arr1 = (int*)malloc(sizeof(int) * 10);
	for (int i = 0; i < 10; i++)
	{
		arr1[i] = i;
	}
	for (int j = 0; j < 10; j++)
	{
		printf("%d ", arr1[j]);
	}
	printf("\n");
	free(arr1);
	arr1 = NULL;

	int* arr2 = (int*)malloc(sizeof(int) * 10);
	if (arr2==NULL)
		printf("malloc fail!");
	for (int i = 0; i < 10; i++)
	{
		arr2[i]=i + 10;
	}
	int* tmp = (int*)realloc(arr2,sizeof(int) * 20);
	if (tmp == NULL)
		printf("realloc fail!");
	for (int j = 10; j < 20; j++)
	{
		arr2[j] = j+10;
	}
	for (int k = 0; k < 20; k++)
	{
		printf("%d ", arr2[k]);
	}
	printf("\n");
	free(arr2);
	arr2 = NULL;

	int* arr3 = (int*)calloc(1,sizeof(int) * 10);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr3[i]);
	}	
	printf("\n");
	free(arr3);
	arr3 = NULL;

	//模拟二维数组
	int** arr4 = (int**)malloc(3 * sizeof(int*));
	for (int i = 0; i < 3; i++)
	{
		arr4[i] = (int*)malloc(5 * sizeof(int));
	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			arr4[i][j] = i * 5 + j;
		}
	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			printf("%2d ", arr4[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	for (int k = 0; k < 3; k++)
	{
		free(arr4[k]);
		arr4[k] = NULL;
	}
	free(arr4);
	arr4 = NULL;
	return 0;
}